package logic

import (
	"context"
	"house_srv/models"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseListLogic) HouseList(in *house.HouseListRequest) (*house.HouseListResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var u models.House
	u.Title = in.Title
	lists, err := u.HouseList()
	if err != nil {
		logx.Error("展示房源列表失败")
		return nil, err
	}
	var houseLists []*house.HouseList
	for _, v := range lists {
		list := house.HouseList{
			Title:       v.Title,
			Price:       float32(v.Price),
			Address:     v.Address,
			Area:        int64(v.Area),
			HouseStatus: int64(v.HouseStatus),
			UserId:      int64(v.UserId),
		}
		houseLists = append(houseLists, &list)
	}
	return &house.HouseListResponse{
		List: houseLists,
	}, nil
}
